<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Orders;

/**
 * OrdersSearch represents the model behind the search form about `app\models\Orders`.
 */
class OrdersSearch extends Orders
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'user_id', 'order_type', 'order_num', 'order_money', 'order_sort'], 'integer'],
            [['order_name', 'order_image', 'order_goto_url', 'order_hint_name', 'order_day_rate', 'order_desc'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Orders::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'order_id' => $this->order_id,
            'user_id' => $this->user_id,
            'order_type' => $this->order_type,
            'order_num' => $this->order_num,
            'order_money' => $this->order_money,
            'order_sort' => $this->order_sort,
        ]);

        $query->andFilterWhere(['like', 'order_name', $this->order_name])
            ->andFilterWhere(['like', 'order_image', $this->order_image])
            ->andFilterWhere(['like', 'order_goto_url', $this->order_goto_url])
            ->andFilterWhere(['like', 'order_hint_name', $this->order_hint_name])
            ->andFilterWhere(['like', 'order_day_rate', $this->order_day_rate])
            ->andFilterWhere(['like', 'order_desc', $this->order_desc]);

        return $dataProvider;
    }
}
